bitkeeper revision 1.1159.32.5 (4121d149RRDPS-silekwHOodPcrI6w)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Tue, 17 Aug 2004 09:35:05 +0000 (09:35 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Tue, 17 Aug 2004 09:35:05 +0000 (09:35 +0000)
First cut of grant-table public interface.

.rootkeys
xen/include/hypervisor-ifs/grant_table.h [new file with mode: 0644]

index f03b2039ecf78ca77aad4524980e30c37bc3d723..4bfb84abd1dd4b7fd37dcc5e7323e77d0b8b14a7 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 404f1bc7IwU-qnH8mJeVu0YsNGMrcw xen/include/hypervisor-ifs/arch-x86_64.h
 3ddb79c2PMeWTK86y4C3F4MzHw4A1g xen/include/hypervisor-ifs/dom0_ops.h
 403cd194j2pyLqXD8FJ-ukvZzkPenw xen/include/hypervisor-ifs/event_channel.h
+4121d149udGfSUGhn3k1ECz0bM31nQ xen/include/hypervisor-ifs/grant_table.h
 3ddb79c25UE59iu4JJcbRalx95mvcg xen/include/hypervisor-ifs/hypervisor-if.h
 40f5623bqoi4GEoBiiUc6TZk1HjsMg xen/include/hypervisor-ifs/io/blkif.h
 40dc4076pVeE1kEEWzcUaNZin65kCA xen/include/hypervisor-ifs/io/domain_controller.h
diff --git a/xen/include/hypervisor-ifs/grant_table.h b/xen/include/hypervisor-ifs/grant_table.h
new file mode 100644 (file)
index 0000000..9c9456b
--- /dev/null
@@ -0,0 +1,89 @@
+/******************************************************************************
+ * grant_table.h
+ * 
+ * Interface for granting foreign access to page frames, and receiving
+ * page-ownership transfers.
+ * 
+ * Copyright (c) 2004, K A Fraser
+ * 
+ * Some rough guidelines on accessing and updating grant-table entries
+ * in a concurreny-safe manner. For more information, Linux contains a
+ * reference implementation for guest OSes (arch/xen/kernel/grant_table.c).
+ * 
+ * NB. WMB is a no-op on current-generation x86 processors.
+ * 
+ * Introducing a valid entry into the grant table:
+ *  1. Write ent->domid.
+ *  2. Write ent->frame (to zero if installing GTF_accept_transfer).
+ *  3. Write memory barrier (WMB).
+ *  4. Write ent->flags, inc. valid type.
+ * 
+ * Removing an unused GTF_permit_access entry:
+ *  1. flags = ent->flags.
+ *  2. Observe that !(flags & (GTF_reading|GTF_writing)).
+ *  3. Check result of SMP-safe CMPXCHG(&ent->flags, flags, 0).
+ *  4. WMB.
+ * 
+ * Removing an unused GTF_accept_transfer entry:
+ *  1. Clear ent->flags.
+ *  2. WMB.
+ * 
+ * Changing a GTF_permit_access from writable to read-only:
+ *  Use SMP-safe CMPXCHG to set GTF_readonly, while checking !GTF_writing.
+ * 
+ * Changing a GTF_permit_access from read-only to writable:
+ *  Use SMP-safe bit-setting instruction.
+ */
+
+#ifndef __HYPERVISOR_IFS_GRANT_TABLE_H__
+#define __HYPERVISOR_IFS_GRANT_TABLE_H__
+
+/*
+ * A grant table comprises a packed array of grant entries in one or more
+ * page frames shared between Xen and a guest.
+ * [XEN]: This field is written by Xen and read by the sharing guest.
+ * [GST]: This field is written by the guest and read by Xen.
+ */
+typedef struct {
+    /* GTF_xxx: various type and flag information.  [XEN,GST] */
+    u16     flags;      /* 0 */
+    /* The domain being granted foreign privileges. [GST] */
+    domid_t domid;      /* 2 */
+    /*
+     * GTF_permit_access: Frame that @domid is allowed to map and access. [GST]
+     * GTF_accept_transfer: Frame whose ownership transferred by @domid. [XEN]
+     */
+    u32     frame;      /* 4 */
+} PACKED grant_entry_t; /* 8 bytes */
+
+/*
+ * Reference to a grant entry in a specified domain's grant table.
+ */
+typedef u16 grant_ref_t;
+
+/*
+ * Type of grant entry.
+ *  GTF_invalid: This grant entry grants no privileges.
+ *  GTF_permit_access: Allow @domid to map/access @frame.
+ *  GTF_accept_transfer: Allow @domid to transfer ownership of one page frame
+ *                       to this guest. Xen writes the page number to @frame.
+ */
+#define GTF_invalid         (0<<0)
+#define GTF_permit_access   (1<<0)
+#define GTF_accept_transfer (2<<0)
+#define GTF_type_mask       (3<<0)
+
+/*
+ * Subflags for GTF_permit_access.
+ *  GTF_readonly: Restrict @domid to read-only mappings and accesses. [GST]
+ *  GTF_reading: Grant entry is currently mapped for reading by @domid. [XEN]
+ *  GTF_writing: Grant entry is currently mapped for writing by @domid. [XEN]
+ */
+#define _GTF_readonly       (2)
+#define GTF_readonly        (1<<_GTF_readonly)
+#define _GTF_reading        (3)
+#define GTF_reading         (1<<_GTF_inuse)
+#define _GTF_writing        (4)
+#define GTF_writing         (1<<_GTF_inuse)
+
+#endif /* __HYPERVISOR_IFS_GRANT_TABLE_H__ */